<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use DateTimeInterface;

class Usersprofile extends Model
{
    protected $table = 'users_profile';
    protected $primaryKey = 'id';

    public static function usersProfileExist($openid)
    {
        return self::select("id")->where("openid",$openid)->first();
    }

    public static function usersProfileDetial($openid)
    {
        return self::select("openid","name","phone","license","idcard","avatar")->where("openid",$openid)->first();
    }

    public static function usersProfileUpdate($openid,$name,$phone,$license,$idcard,$avatar)
    {
        return self::where("openid",$openid)->update(["name"=>$name,"phone"=>$phone,"license"=>$license,"idcard"=>$idcard,"avatar"=>$avatar]);
    }

    public static function usersProfileAdd($openid,$name,$phone,$license,$idcard,$avatar)
    {
        return self::insertGetId(["openid"=>$openid,"name"=>$name,"phone"=>$phone,"license"=>$license,"idcard"=>$idcard,"avatar"=>$avatar,"created_at"=>time()]);
    }
}